package validate

import (
	"github.com/go-playground/validator/v10"
	"go-project/dto/requrest"
	"go-project/models"
)

func RolesNameUniqueValidate(field validator.FieldLevel) bool {
	rolos := &models.Roles{}
	name := field.Field().String()
	param := field.Param()
	var id uint
	if param == "update" {
		i := field.Parent().Interface()
		request := i.(requrest.RolesUpdateRequest)
		id = request.ID
	}
	if rolos.CheckNameExist(name, id) {
		return false
	}
	return true
}

func RolesKeyUniqueValidate(field validator.FieldLevel) bool {
	rolos := &models.Roles{}
	name := field.Field().String()
	param := field.Param()
	var id uint
	if param == "update" {
		i := field.Parent().Interface()
		request := i.(requrest.RolesUpdateRequest)
		id = request.ID
	}
	if rolos.CheckKeyExist(name, id) {
		return false
	}
	return true
}
